<template>
    <view class="container">
        <!-- 评价部分 -->
        <view class="section">
            <view class="section-title">
                <text class="evaluate-target">评价对象</text>
                <text class="evaluate-target-info">{{currentTripDetails.order.line.real_name}}({{ currentTripDetails.order.line.phone }})</text>
            </view>
            <view class="evaluate-icon-info">
                <view class="evaluate-icon-info-item" @click="handleGoodEvaluate">
                    <text :class="{ 'text-check': isGood }">好评</text>
                    <image v-if="isGood" class="evaluate-icon" src="/static/personalCenter/zan.png" mode="aspectFill">
                    </image>
                    <image v-if="!isGood" class="evaluate-icon" src="/static/personalCenter/gray-zan.png"
                        mode="aspectFill"></image>
                </view>
                <view class="evaluate-icon-info-item" @click="handleBadEvaluate">
                    <text :class="{ 'text-check': isBad }">差评</text>
                    <image v-if="isBad" class="evaluate-icon" src="/static/personalCenter/bad.png" mode="aspectFill">
                    </image>
                    <image v-if="!isBad" class="evaluate-icon" src="/static/personalCenter/gray-bad.png"
                        mode="aspectFill"></image>
                </view>
            </view>
            <view class="evaluate-input">
                <textarea placeholder="评价详情" maxlength="100" v-model="evaluateDetail"
                    @input="countEvaluateChars"></textarea>
                <text class="char-count">{{ evaluateCharCount }}/100</text>
            </view>
        </view>

        <!-- 提交按钮 -->
        <view class="submit-btn" @click="submit">提 交</view>

    </view>
</template>

<script>
export default {
    data() {
        return {
            isGood: false,
            isBad: false,
            evaluateDetail: "",
            evaluateCharCount: 0,
            currentTripId: null,
            currentTripDetails: {}
        };
    },
    onLoad(options) {
        this.currentTripId = options.id
        this.getPassengerTripDetails()
    },
    computed: {
        // 表单验证
        isCanSubmit() {
            if ((this.isGood || this.isBad) && this.evaluateDetail) {
                return true
            }
            return false
        }
    },
    methods: {
        countEvaluateChars(e) {
            this.evaluateCharCount = e.detail.value.length;
        },
        handleGoodEvaluate() {
            this.isBad = false
            this.isGood = !this.isGood
        },
        handleBadEvaluate() {
            this.isGood = false
            this.isBad = !this.isBad
        },
        async getPassengerTripDetails() {
            try {
                const res = await this.$http.get(`/h5/user/trip/passengerDetail/${this.currentTripId}`)
                this.currentTripDetails = res.data

            } catch (error) { }
        },
        // 提交乘客评价
        async submit() {
            if (!this.isCanSubmit) {
                uni.showToast({
                    title: "请完善评价信息",
                    icon: "none",
                });
                return;
            }
            let params = {
                type: this.isGood ? 1 : 2,
                content: this.evaluateDetail
            }
            try {
                const res = await this.$http.post(`/h5/user/trip/evaluate/${this.currentTripId}`, params);
                uni.showToast({
                    title: "提交成功",
                    icon: "success",
                });
                setTimeout(() => {
                    uni.navigateBack();
                }, 1000);
            } catch (error) {}
        },
    },
};
</script>

<style scoped>
.container {
    padding: 20rpx 26rpx;
    height: 100%;
}

.section {
    background-color: #fff;
    padding: 26rpx 40rpx;
    margin-bottom: 20rpx;
    border-radius: 16rpx;
    height: 100%;
}

.section-title {
    padding-bottom: 26rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-title .evaluate-target {
    font-size: 32rpx;
    font-weight: 500;
    color: #0B1F20;
}

.section-title .evaluate-target-info {
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: 28rpx;
    color: #999999;
}

.evaluate-icon-info {
    display: flex;
    justify-content: space-between;
    margin: 34rpx 122rpx;
}

.evaluate-icon-info-item {
    display: flex;
    align-items: center;

}

.evaluate-icon-info-item text {
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: 32rpx;
    color: #999999;
}

.evaluate-icon-info-item .text-check {
    color: #FF7937;
}

.evaluate-input {
    position: relative;
}

.evaluate-icon {
    width: 48rpx;
    height: 48rpx;
    margin-left: 22rpx;
}

textarea {
    width: 100%;
    height: 320rpx;
    padding: 28rpx 24rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: 28rpx;
    color: #999999;
    background: #F5F5F6;
    border-radius: 16rpx;
    box-sizing: border-box;
}

.char-count {
    position: absolute;
    right: 24rpx;
    bottom: 28rpx;
    font-size: 28rpx;
    color: #999;
}


.submit-btn {
    background: linear-gradient(90deg, #ff3f39 0%, #ff7937 100%);
    color: #fff;
    text-align: center;
    padding: 24rpx 0;
    border-radius: 16rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 500;
    font-size: 36rpx;
    color: #FFFFFF;
    margin-bottom: 20rpx;
}
</style>
